package com.tedu.openmedical.medicalsystem.user.controller;

import com.tedu.openmedical.base.response.JsonResult;
import com.tedu.openmedical.medicalsystem.user.pojo.dto.UserLoginParam;
import com.tedu.openmedical.medicalsystem.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/v1/user/")
@Api(tags = "用户模块")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    @ApiOperation(value = "用户登录", notes = "用户登录接口")
    public JsonResult login(UserLoginParam userLoginParam, HttpServletRequest httpServletRequest){
        return JsonResult.ok(userService.login(userLoginParam, httpServletRequest));
    }

    //@RequiresRoles("admin")
    @GetMapping("selectAll")
    @ApiOperation(value = "查询所有用户", notes = "查询所有用户接口")
    public JsonResult selectAll(){
        return JsonResult.ok(userService.selectAll());
    }

    @GetMapping("/unauthorized/{message}")
    public JsonResult unauthorized(@PathVariable("message") String message) {
        return JsonResult.ok(message);
    }
}
